import {
  TableBaseColumn,
  TableColumnGroup,
  TableSelectionColumn,
  TableExpandColumn,
  InternalRowData
} from 'naive-ui/es/data-table/src/interface'

type DictOptions = {
  value?: string | number | boolean
  label?: string | number
  children?: DictOptions[]
  props?: {
    [index: string]: unknown
  }
  type?: 'default' | 'primary' | 'info' | 'success' | 'warning' | 'error'
}

export type CommonProColumnInfo = {
  type?:
    | 'selection'
    | 'expand'
    | 'dict'
    | 'tag'
    | 'link'
    | 'switch'
    | 'date'
    | 'index'
  props?: {
    [index: string]: unknown
  }
  dictOptions?: DictOptions[]
  valueCode?: string
  labelCode?: string
  dictCode?: number | string
  format?: string
  checkedText?: string
  uncheckedText?: string
  visiable?: boolean
  displayValue?: (row?: any, index?: number) => any
  query?: Partial<ProtableQueryItem>
  click?: (row?: any, index?: number) => any
}

type ProTableBaseColumn<T> = TableBaseColumn<T> & CommonProColumnInfo
type ProTableColumnGroup<T> = TableColumnGroup<T> & CommonProColumnInfo
type ProTableSelectionColumn<T> = Omit<TableSelectionColumn<T>, 'type'> &
  CommonProColumnInfo
type ProTableExpandColumn<T> = Omit<TableExpandColumn<T>, 'type'> &
  CommonProColumnInfo

export type ProTableColumn<T = InternalRowData> =
  | ProTableBaseColumn<T>
  | ProTableColumnGroup<T>
  | ProTableSelectionColumn<T>
  | ProTableExpandColumn<T>

export type ProtableQueryItem = {
  type?:
    | 'select'
    | 'input'
    | 'date'
    | 'year'
    | 'daterange'
    | 'cascader'
    | 'inputNumber'
  title: any
  key: string | string[]
  multiple?: boolean
  placeholder?: string
  value?: number | string | boolean | string[]
  dictOptions?: DictOptions[]
  dictCode?: number | string
  checkStrategy?: 'child' | 'all'
  showPath?: boolean
  labelWidth?: number | string | 'auto'
  labelAlign?: 'left' | 'right'
  render?: any
  order?: number
  defaultValue?: any
  span?: number | string
  props?: any
}

export type ProTableRequest = (
  pages?: any,
  query?: any
) => {
  data?: any[]
  total?: number
  error?: any
}

export type ProTableInst = {
  excelExportDownload: () => void
  reload: () => void
  search: (params?: Record<string, string>) => void
  reset: () => void
}
